/*
* Copyright 2017 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-service-dealer
*
* @File name : RoadSOSController.java
*
* @Author : Administrator
*
* @Date : 2017年12月5日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2017年12月5日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmmc.service.dealer.controller;


import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.marketing.common.Response;
import org.marketing.common.constants.ResultMsgConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.yonyou.gmmc.service.dealer.constant.DealerConstant;
import com.yonyou.gmmc.service.dealer.model.TtSoshelp;
import com.yonyou.gmmc.service.dealer.service.RoadSosService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
*
* @author Administrator
* 企业号道路救援API
* @date 2017年12月5日
*/
@RestController
@RequestMapping(value = DealerConstant.BASE_PATH + "/" + DealerConstant.VERSION)
@Api("企业号道路救援API")
public class RoadSosController {

    private Logger logger = Logger.getLogger(RoadSosController.class);
    
    @Autowired
    private RoadSosService roadSosService;
    
    
	/**
	 * 道路救援列表查询
	 * @author QuanKK
	 * @date 2018年1月19日 下午5:45:46
	 * @param pageNum
	 * @param pageSize
	 * @param userPhone
	 * @param status
	 * @param phone
	 * @return
	 */
	@RequestMapping(value = "/querySosHelp", method = RequestMethod.GET)
	@ApiOperation(value = "道路救援列表查询", notes = "道路救援列表查询")
	public Response<PageInfo<TtSoshelp>> roadSosList(
			@RequestParam(required = false, defaultValue = "10") Integer pageNum
			, @RequestParam(required = false, defaultValue = "10") String pageSize
			, @RequestParam(required = false, defaultValue = "") String userPhone 	// 客户电话
			, @RequestParam(required = false, defaultValue = "") Integer status     // 救援状态  0:全部; 10111001:待救援; 10111002:救援中; 10111003:救援完成; 10111004:救援取消; 10111005:救援完成; 
			, @RequestParam("phone") String phone        							// 售后顾问电话
	) {
		logger.info("用户》》》》》" + phone);
		try {
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("pageNum", pageNum);
			paramMap.put("pageSize", pageSize);
			paramMap.put("userPhone", userPhone);
			paramMap.put("status", status);
			paramMap.put("phone", phone);
			PageInfo<TtSoshelp> result = roadSosService.querySosHelp(paramMap);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * 道路救援详情查询
	 * @author QuanKK
	 * @date 2018年1月26日 下午4:31:40
	 * @param userPhone
	 * @param status
	 * @param phone
	 * @return
	 */
	@RequestMapping(value = "/querySosDetail", method = RequestMethod.GET)
	@ApiOperation(value = "道路救援详情查询", notes = "道路救援详情查询")
	public Response<TtSoshelp> querySosDetail(
			@RequestParam(required = true) Long soshelpId    						// 救援ID
			, @RequestParam("phone") String phone									// 售后顾问电话
	) {
		logger.info("用户》》》》》" + phone);
		try {
			TtSoshelp result = roadSosService.querySosDetail(soshelpId,phone);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * @author QuanKK
	 * @date 2018年1月26日 下午5:07:40
	 * @param soshelpId
	 * @param phone
	 * @return
	 */
	@RequestMapping(value = "/rescueSos", method = RequestMethod.POST)
	@ApiOperation(value = "立即救援", notes = "立即救援")
	public Response<Map<String, Object>> rescue(
			@RequestParam(required = true) Long soshelpId    						// 救援ID
			, @RequestParam("phone") String phone									// 售后顾问电话
	) {
		logger.info("用户》》》》》" + phone);
		try {
			Map<String, Object> result = roadSosService.rescueSos(soshelpId,phone);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * @author QuanKK
	 * @date 2018年1月26日 下午5:07:40
	 * @param soshelpId
	 * @param phone
	 * @return
	 */
	@RequestMapping(value = "/cancelSos", method = RequestMethod.POST)
	@ApiOperation(value = "取消救援", notes = "取消救援")
	public Response<Map<String, Object>> cancelSos(
			@RequestParam(required = true) Long soshelpId    						// 救援ID
			, @RequestParam("phone") String phone									// 售后顾问电话
	) {
		logger.info("用户》》》》》" + phone);
		try {
			Map<String, Object> result = roadSosService.cancelSos(soshelpId,phone);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * @author QuanKK
	 * @date 2018年1月26日 下午5:07:40
	 * @param soshelpId
	 * @param phone
	 * @return
	 */
	@RequestMapping(value = "/completeSos", method = RequestMethod.POST)
	@ApiOperation(value = "完成救援", notes = "完成救援")
	public Response<Map<String, Object>> completeSos(
			@RequestParam(required = true) Long soshelpId    						// 救援ID
			, @RequestParam("phone") String phone									// 售后顾问电话
	) {
		logger.info("用户》》》》》" + phone);
		try {
			Map<String, Object> result = roadSosService.completeSos(soshelpId,phone);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	
    
    
    
    
}
